package com.config;


import com.interceptor.ResourceInterceptor;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

@Configuration
@ComponentScan("com.controller")
@EnableWebMvc
public class SpringMvcConfig implements WebMvcConfigurer {
    //开启情态资源的释放

    @Override
    public void configureDefaultServletHandling(DefaultServletHandlerConfigurer defaultServletHandlerConfigurer) {
        defaultServletHandlerConfigurer.enable();
        // 默认静态资源处理器
    }

    @Override
    public void configureViewResolvers(ViewResolverRegistry resolverRegistry) {
        resolverRegistry.jsp("/admin/", ".jsp");
    }

    /*
     * 在注册的拦截器类中添加自定义拦截器
     * addPathPatterns()方法设置拦截的路径
     * excludePathPatterns()方法设置不拦截的路径
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new ResourceInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**","/img/**","js/**");
    }
}
